package com.wanmait.recruitment.controller;

import com.github.pagehelper.PageInfo;
import com.wanmait.recruitment.pojo.WebMenu;
import com.wanmait.recruitment.service.ConfigService;
import com.wanmait.recruitment.service.WebMenuService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("manage/menu")
public class MenuController {

    @Resource
    private ConfigService configService;
    @Resource
    private WebMenuService webMenuService;
    @RequestMapping("list")
    public  void list(){

    }
    @RequestMapping("listdata")
    @ModelAttribute("pageInfo")
    public  PageInfo<WebMenu> listdata(Integer pageNum,String title){
        //每页显示条数
        int pageSize;
        try {
            pageSize= Integer.parseInt(configService.getValueByKey("manage_web_menu_count"));
        } catch (NumberFormatException e) {
            pageSize=Integer.parseInt(configService.getDefaultValueByKey("manage_web_menu_count"));
        }
        //PageInfo<WebMenu>pageInfo=webMenuService.findPage(pageNum,pageSize);
        return webMenuService.findPage(pageNum,pageSize,title);

    }
    @RequestMapping("insert")
    public  void insert(){

    }
    @RequestMapping("delete")
    @ResponseBody
    public  void delete(Integer id){
        webMenuService.delete(id);

    }
   @RequestMapping("batchDelete")
   @ResponseBody
    public  void batchDelete(String ids){

        webMenuService.delete(ids);

    }
   @PostMapping("addWebMenu")
    public  String addWebMenu(WebMenu webMenu){

       System.out.println(webMenu);
       webMenuService.insert(webMenu);

        return  "redirect:/manage/menu/list";

    }
   @RequestMapping("update")
    public  void update(WebMenu webMenu){
       System.out.println(webMenu);

         webMenuService.update(webMenu);

    }
}
